package FunctionPackage;

import BookListPackage.BookList;

import java.util.Scanner;

public class Remove implements Function {
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书！");
        System.out.println("请输入要删除的书名:");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();

        //遍历循环找到书本
        for (int i = 0; i < bookList.amount; i++) {
            if (bookName.equals(bookList.books[i].getBookName())) {
                //找到该书本了，尾删。
                if (i == bookList.amount - 1) {
                    bookList.amount--;
                }else {
                    //1,2,3,4,5,6
                    //0,1,2,3,4,5
                    for (int j = i; j < bookList.amount - 1; j++) {
                        bookList.books[j] = bookList.books[j+1];
                    }
                    bookList.amount--;
                    System.out.println("-------删除成功！！！------");
                    return;
                }

            }
        }
        System.out.println("---------未找到该书籍，删除失败！！！--------");
    }

}
